package Test_1116;

import java.util.*;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
class MinStack {
    //建立两个栈：普通栈、最小栈
    public Stack<Integer> stack;
    public Stack<Integer> minStack;
    public MinStack() {
        stack=new Stack<>();
        minStack=new Stack<>();
    }
    //将元素放入栈中
    //判断是否为空
    //如果为空，将元素放到普通栈和最小栈；
    //不为空放到普通栈中，如果放到普通栈中的元素小于最小栈，放到最小栈中
    public void push(int val) {
        if(isEmpty()){
            stack.push(val);
            minStack.push(val);
        }else{
            stack.push(val);
            if(val<=minStack.peek()){
                minStack.push(val);
            }
        }
    }
    //判断为空
    // 两个同时为空则为空
    public boolean isEmpty(){
        return stack.empty()&&minStack.empty();
    }
    //删除栈顶元素
    //判断是否为空，为空返回；
    //不为空，返回栈顶元素，判断最小栈中是否有该删除的元素，有则删除最小栈中的元素；
    public void pop() {
        if(isEmpty()){
            return;
        }

        if(stack.peek().equals(minStack.peek())){
            minStack.pop();
        }
        stack.pop();
    }
    //获取栈堆顶部元素
    //判断是否为空
    //不为空，获取栈顶元素
    public int top() {
        if(isEmpty()){
            return -1;
        }
        int val=stack.peek();
        return val;
    }
    //获取栈堆顶部元素
    //判断是否为空
    //不为空，获取栈顶元素
    public int getMin() {
        if(isEmpty()){
            return -1;
        }
        int val=minStack.peek();
        return val;
    }
}
public class Test {
    public static void main(String[] args) {
        Solution solution=new Solution();
        String[] n={"2","1","+","3","*"};
        //System.out.println(solution.evalRPN(n));
    }
    public static void main7(String[] args) {
        minStack minStack=new minStack();
        minStack.push(512);
        minStack.push(-1024);
        minStack.push(-1024);
        minStack.push(512);
        minStack.pop();
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.getMin());
    }
    public static void main6(String[] args) {
        MyQueue queue=new MyQueue();
        //入队
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        //获取有效元素个数
        //System.out.println(queue.size());//3
        //获取队头元素
        System.out.println(queue.peek());//1
        //出队
        System.out.println(queue.poll());//1
    }
    public static void main5(String[] args) {
        int[] n={1,2,3};
        MyStack stack=new MyStack(n);
        //入栈
        stack.push(1);
        stack.push(2);
        stack.push(3);
        //获取有效个数大小
        //System.out.println(stack.size());//3
        //获取栈顶元素
        System.out.println(stack.peek());//3
        //出栈
        stack.pop();
        //获取栈顶元素
        System.out.println(stack.peek());//2
        //查找元素下标
        //System.out.println(stack.search(2));

    }
    public static void main4(String[] args) {
        Queue<Integer> queue=new LinkedList<>();
        //入队
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        //获取有效元素个数
        System.out.println(queue.size());//3
        //获取队头元素
        System.out.println(queue.peek());//1
        //出队
        System.out.println(queue.poll());//1
    }
    public static void main2(String[] args) {
        Queue<Integer> queue=new LinkedList<>();
        Queue<Integer> queue1=new ArrayDeque<>();
        Queue<Integer> queue2=new PriorityQueue<>();
    }
    public static void main1(String[] args) {
        Stack<Integer> stack=new Stack<>();
        //入栈
        stack.push(1);
        stack.push(2);
        stack.push(3);
        //获取有效个数大小
        System.out.println(stack.size());//3
        //获取栈顶元素
        System.out.println(stack.peek());//3
        //出栈
        stack.pop();
        //获取栈顶元素
        System.out.println(stack.peek());//2
        //查找元素下标
        System.out.println(stack.search(2));
    }
}
